﻿Imports BUS
Imports DTO

Public Class frmtracuudocgia

    Private Sub frmtracuudocgia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dsldg As New List(Of LoaiDocGiaDTO)()
        Dim busdg As New LoaiDocGiaBUS()
        dsldg = busdg.LayDSLoaiDocGia()
        LookUploaidocgia.Properties.DataSource = dsldg
        LookUploaidocgia.Properties.DisplayMember = "TenLoaiDocGia"
        LookUploaidocgia.Properties.ValueMember = "MaLoaiDocGia"
        LookUploaidocgia.EditValue = 1
    End Sub

    Dim docgia As New DocGiaCRT()

    Private Sub CapNhatTieuChuanTraCuu(ByVal a As Boolean)
        If a = True Then
            If txtmadocgia.Text <> "" Then
                docgia.MaDocGia = Integer.Parse(txtmadocgia.Text)
            Else
                docgia.MaDocGia = 0
            End If

            docgia.TenDocGia = txttendocgia.Text
            docgia.NgaySinhTu = DateEditngaysinhtu.DateTime
            docgia.NgaySinhDen = DateEditngaysinhden.DateTime
            docgia.NgayLapTheTu = DateEditngaylapthetu.DateTime
            docgia.NgayLapTheDen = DateEditngaylaptheden.DateTime
            docgia.DiaChi = txtdiachi.Text
            docgia.Email = txtemail.Text
            docgia.MaLoaiDocGia = LookUploaidocgia.EditValue

            docgia.ChkNgaySinh = chkngaysinh.Checked
            docgia.ChkNgayLapThe = chkngaylapthe.Checked
            docgia.ChkDiaChi = chkdiachi.Checked
            docgia.ChkEmail = chkemail.Checked
            docgia.ChkLoaiDocGia = chkloaidocgia.Checked
        End If
    End Sub

    Private Sub btntracuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntracuu.Click
        Try
            CapNhatTieuChuanTraCuu(True)
            Dim hsBus As New DocGiaBUS()
            Dim dtHS As DataTable
            dtHS = hsBus.TimKiem(docgia)
            dtgvdocgia.DataSource = dtHS
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub chkngaysinh_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkngaysinh.CheckedChanged
        If chkngaysinh.Checked Then
            DateEditngaysinhtu.Enabled = True
            DateEditngaysinhden.Enabled = True
        Else
            DateEditngaysinhtu.Enabled = False
            DateEditngaysinhden.Enabled = False
        End If
    End Sub

    Private Sub chkngaylapthe_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkngaylapthe.CheckedChanged
        If chkngaylapthe.Checked Then
            DateEditngaylapthetu.Enabled = True
            DateEditngaylaptheden.Enabled = True
        Else
            DateEditngaylapthetu.Enabled = False
            DateEditngaylaptheden.Enabled = False
        End If
    End Sub

    Private Sub chkdiachi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkdiachi.CheckedChanged
        If chkdiachi.Checked Then
            txtdiachi.Enabled = True
        Else
            txtdiachi.Enabled = False
        End If
    End Sub

    Private Sub chkemail_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkemail.CheckedChanged
        If chkemail.Checked Then
            txtemail.Enabled = True
        Else
            txtemail.Enabled = False
        End If
    End Sub

    Private Sub chkloaidocgia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkloaidocgia.CheckedChanged
        If chkloaidocgia.Checked Then
            LookUploaidocgia.Enabled = True
        Else
            LookUploaidocgia.Enabled = False
        End If
    End Sub
End Class